package cn.xinyangtong.sso.service.impl;

import cn.xinyangtong.mapper.TbUserMapper;
import cn.xinyangtong.pojo.TbUser;
import cn.xinyangtong.pojo.TbUserExample;
import cn.xinyangtong.sso.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;

/**
 * Created by fengbo on 2017/8/1.
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private TbUserMapper userMapper;

    @Override
    public TbUser selectUserByUserNameAndPassword(String username, String password) {
        //加盐
//        password = "sjlkjslsjl" + password + "lksjflsj";
        TbUserExample example = new TbUserExample();
        TbUserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username).andPasswordEqualTo(//
                DigestUtils.md5DigestAsHex(password.getBytes()));
        List<TbUser> users = userMapper.selectByExample(example);
        if (users != null && users.size() > 0) {
            TbUser user = users.get(0);
            return user;
        }
        return null;
    }

}
